package com.bytedance.retrofit2;

import com.bytedance.retrofit2.client.ClientCall;
import com.bytedance.retrofit2.client.SsResponse;

public final class CallbackRunnable<T> implements Runnable {
    public final SsCall<T> ssHttpCall;
    private final Callback<T> callback;

    CallbackRunnable(SsCall ssHttpCall, Callback callback) {
        this.ssHttpCall = ssHttpCall;
        this.callback = callback;
    }

    public synchronized final void run() {
        try {
            ssHttpCall.executed = true;
            ClientCall call = ssHttpCall.rawCall;
            Throwable creationFailure = ssHttpCall.creationFailure;
            if (call != null) {
            } else if (creationFailure != null) {
            } else {
                call = ssHttpCall.createRawCall();
                ssHttpCall.rawCall = call;
            }
            if (creationFailure == null) {
                if (ssHttpCall.canceled) {
                    call.cancel();
                }
                SsResponse response = call.execute();
                ResponseWrapper<T> responseWrapper = this.ssHttpCall.parseResponse(response);
                ssHttpCall.interceptResponse(call, responseWrapper);
                callback.onCacheResponse(responseWrapper);
            } else {
                callback.onErrorResponse(creationFailure);
            }
        } catch (Throwable throwable) {
            throwable.printStackTrace();
        }
    }
}

